package com.example.idachuappone.index.dto;

import android.content.Context;
import com.example.idachuappone.index.entity.FamilyFeast;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

public class FamilyFeastDto {
    public List<FamilyFeast> getFamilyFeastList(Context context, String json) throws Exception {
        JSONObject jsonObject = new JSONObject(json);
        if (jsonObject.getInt("code") == 10000) {
            List<FamilyFeast> list = new ArrayList();
            JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("results");
            for (int i = 0; i < jsonArray.length(); i++) {
                list.add(new FamilyFeast().parseJson(jsonArray.getJSONObject(i)));
            }
            return list;
        }
        throw new Exception(jsonObject.getString("error"));
    }

    public FamilyFeast getFamilyFeast(Context context, String json) throws Exception {
        JSONObject jsonObject = new JSONObject(json);
        if (jsonObject.getInt("code") == 10000) {
            return new FamilyFeast().parseJson(jsonObject.getJSONObject("data"));
        }
        throw new Exception(jsonObject.getString("error"));
    }
}
